package engine;
import java.util.*;
public class physicsCalculator {

	/**
	 * physicsCalculator Constructor
	 */
	public physicsCalculator()
	{
		
	}
	/**
	 * startUp, called to begin the command line physics calculator
	 */
	public void startUp()
	{
		Scanner keyboard = new Scanner(System.in);
		System.out.println("Welcome to the physics calculator.");
		while(true){
			System.out.println("What are you looking to solve for?");
			String solving = keyboard.next().toLowerCase();
			if(solving.equals("acceleration"))
			{
				System.out.println("To solve for Acceleration I'll need an initial velocity, a time and a final velocity or n object's mass and its force");
				System.out.println("Enter 1 for the first option or 2 for the second.");
				int choice = 0;
				try{
				choice = keyboard.nextInt();
				}catch(InputMismatchException e){choice = 3;}
				
				if(choice==1)
				{
					System.out.println("Initial Velocity? (as a magnitude in m/s)");
					float velocity = keyboard.nextFloat();
					System.out.println("Final Velocity? (as a magnitude in m/s)");
					float v2 = keyboard.nextFloat();
					System.out.println("Time? (in s)");
					float time = keyboard.nextFloat();
					System.out.println("Acceleration equals "+PhysicsFunctions.accel(velocity, v2, time)+" m/s/s");
				}
				else if(choice ==2)
				{
					System.out.println("Mass? (in kg)");
					float mass = keyboard.nextFloat();
					System.out.println("Force? (in Newtons)");
					float force = keyboard.nextFloat();
					System.out.println("Acceleration equals "+PhysicsFunctions.accel(mass, force)+" m/s/s");
				}
				else
				{
					System.out.println("That's not a choice...");
				}

			}
			else if(solving.equals("force"))
			{
				System.out.println("To solve for a force, I'll need a mass and an acceleration");
				System.out.println("Mass? (in kg)");
				float mass = keyboard.nextFloat();
				System.out.println("Acceleration? (in m/s/s)");
				float accel = keyboard.nextFloat();
				System.out.println("The force of such an object would equal "+PhysicsFunctions.force(mass, accel)+" joules");

			}
			else if(solving.equals("time"))
			{
				System.out.println("To solve for Time I'll need an initial velocity, an acceleration and a final velocity");
				System.out.println("Initial Velocity? (as a magnitude in m/s)");
				float velocity = keyboard.nextFloat();
				System.out.println("Final Velocity? (as a magnitude in m/s)");
				float v2 = keyboard.nextFloat();
				System.out.println("Acceleration? (in m/s/s)");
				float time = keyboard.nextFloat();
				System.out.println("Time equals "+PhysicsFunctions.time(velocity, v2, time)+" m/s/s");
			}
			else if(solving.equals("velocity"))
			{
				System.out.println("To solve for Velocity I'll need an initial velocity, a time and an acceleration or n object's momentum and its mass");
				System.out.println("Enter 1 for the first option or 2 for the second.");
				int choice = 0;
				try{
				choice = keyboard.nextInt();
				}catch(InputMismatchException e){choice = 3;}
				
				if(choice==1)
				{
					System.out.println("Initial Velocity? (as a magnitude in m/s)");
					float velocity = keyboard.nextFloat();
					System.out.println("Time? (in s)");
					float time = keyboard.nextFloat();
					System.out.println("Acceleration? (in m/s/s)");
					float accel = keyboard.nextFloat();
					System.out.println("Velocity equals "+PhysicsFunctions.velocity(velocity, accel, time)+" m/s");
				}
				else if(choice ==2)
				{
					System.out.println("Momentum? (X component in Newton-Seconds)");
					float momentumX = keyboard.nextFloat();
					System.out.println("Momentum? (Y component in Newton-Seconds)");
					float momentumY = keyboard.nextFloat();
					System.out.println("Mass? (in kg)");
					float mass = keyboard.nextFloat();
					Vector temp = PhysicsFunctions.velocity(new Vector(momentumX,momentumY),mass);
					System.out.println("The velocity equals "+temp.magnitude()+" m/s");
					System.out.println(""+temp.getX()+" m/s in the X direction");
					System.out.println(""+temp.getY()+" m/s in the Y direction");
				}
				else
				{
					System.out.println("That's not a choice...");
				}

			}
			else if(solving.equals("position"))
			{
				System.out.println("To solve for a position, I'll need an initial position, initial velocity, a time and an acceleration");
				System.out.println("Initial Position's X coordinate? (in m)");
				float intPosX = keyboard.nextFloat();
				System.out.println("Initial Position's Y coordinate? (in m)");
				float intPosY = keyboard.nextFloat();
				System.out.println("Initial Velocity's X component? (in m/s)");
				float intVelX = keyboard.nextFloat();
				System.out.println("Initial Velocity's Y component? (in m/s)");
				float intVelY = keyboard.nextFloat();
				System.out.println("Acceleration's X component? (in m/s/s)");
				float AccelX = keyboard.nextFloat();
				System.out.println("Acceleration's Y component? (in m/s/s)");
				float AccelY = keyboard.nextFloat();
				System.out.println("Time? (in s)");
				float time = keyboard.nextFloat();
				Vector initPos = new Vector(intPosX,intPosY);
				Vector intVel = new Vector(intVelX,intVelY);
				Vector accel = new Vector(AccelX,AccelY);
				Vector position = PhysicsFunctions.position(initPos, intVel, time, accel);
				System.out.println("Position would be ("+position.getX()+","+position.getY()+")");
			}
			else if(solving.equals("mass"))
			{
				System.out.println("To solve for Mass I'll need an acceleration and a force or an object's momentum and its velocity");
				System.out.println("Enter 1 for the first option or 2 for the second.");
				int choice = 0;
				try{
				choice = keyboard.nextInt();
				}catch(InputMismatchException e){choice = 3;}
				if(choice==1)
				{
					System.out.println("Acceleration? (as a magnitude in m/s/s)");
					float accel = keyboard.nextFloat();
					System.out.println("Force? (in Newtons)");
					float force = keyboard.nextFloat();
					System.out.println("Mass equals "+PhysicsFunctions.mass(accel,force)+" kg");
				}
				else if(choice ==2)
				{
					System.out.println("Momentum? (X component in Newton-Seconds)");
					float momentumX = keyboard.nextFloat();
					System.out.println("Momentum? (Y component in Newton-Seconds)");
					float momentumY = keyboard.nextFloat();
					
					System.out.println("Velocity? (X component in m/s)");
					float velX = keyboard.nextFloat();
					System.out.println("Velocity? (Y component in m/s)");
					float velY = keyboard.nextFloat();
					
					Vector momentum = new Vector(momentumX,momentumY);
					Vector velocity = new Vector(velX,velY);
					
					System.out.println("The Mass equals "+PhysicsFunctions.mass(momentum, velocity)+" kg");
				}
				else
				{
					System.out.println("That's not a choice...");
				}

			}
			else if(solving.equals("momentum"))
			{
				System.out.println("To solve for Momentum I'll need a mass and a velocity");
				System.out.println("Mass? (in kg)");
				float mass = keyboard.nextFloat();
				System.out.println("Velocity? (X component in m/s)");
				float velX = keyboard.nextFloat();
				System.out.println("Velocity? (Y component in m/s)");
				float velY = keyboard.nextFloat();
				Vector velocity = new Vector(velX,velY);
				Vector momentum = PhysicsFunctions.momentum(mass, velocity);
				System.out.println("The momentum equals "+momentum.magnitude()+" Newton-seconds");
				System.out.println(""+momentum.getX()+" Newton-seconds in the X direction");
				System.out.println(""+momentum.getY()+" Newton-seconds in the Y direction");
			}
			else if(solving.equals("kinetic_energy"))
			{
				System.out.println("To solve for Kinetic Energy I'll need a mass and a velocity");
				System.out.println("Mass? (in kg)");
				float mass = keyboard.nextFloat();
				System.out.println("Velocity? (X component in m/s)");
				float velX = keyboard.nextFloat();
				System.out.println("Velocity? (Y component in m/s)");
				float velY = keyboard.nextFloat();
				
				Vector velocity = new Vector(velX,velY);
				
				System.out.println("The Kinetic Energy equals "+PhysicsFunctions.kineticEnergy(mass,velocity));

			}
			else if(solving.equals("q")||solving.equals("quit"))
			{
				System.out.println("Good-bye");
				return;
			}
			else if(solving.equals("help"))
			{
				System.out.println("I can help you solve for\nacceleration\nkinetic_energy\nforce\nmass\nmomentum\nposition\ntime\nvelocity");
			}
			else
			{
				System.out.println("I'm sorry, I didn't understand that.Try typing \"help\" for a list of options");			
			}
		}

	}
	public static void main(String args[])
	{
		physicsCalculator mine = new physicsCalculator();
		mine.startUp();
	}
}
